angular.module('imsApp').controller('channelModalController', ['$scope', 'ChannelsManager','param','$uibModalInstance', function ($scope, ChannelsManager,param,$uibModalInstance) {
    $scope.param = param;
    $scope.total = 0;

    $scope.modelOk = function ($event) {
        $event.preventDefault();
        $uibModalInstance.close(this.item);
    };

    $scope.modelCancel = function () {
        $uibModalInstance.dismiss("cancel");
    };

    $scope.search = function (event) {
        if (!event || event.keyCode == 13) {
            $scope.isReset = true;
            $scope.paginationConf.search = true;
        }
    };
    $scope.paginationConf = {
        currentPage: 1,
        itemsPerPage: 10,
        pagesLength: 9,
        perPageOptions: [10, 20, 30, 40, 50],
        search: true,
        onChange: function () {
            ChannelsManager.channelsList([$scope.isReset ? 1 : this.currentPage, this.itemsPerPage],
                {"keyword": $scope.keyword}).then(
                function (result) {
                    console.log(result)
                    if (result.data.c == 's') {
                        $scope.param.item = result.data.pageList;
                        $scope.paginationConf.totalItems = result.data.total;
                    }else {
                        alert(result.i);
                    }
                },
                function (error) {
                    alert(error);
                }
            )

            if ($scope.isReset) {
                $scope.isReset = false;
            }
        }
    };
}])

